# -*- coding:utf-8 -*-
import uuid
from datetime import datetime
from werkzeug.security import generate_password_hash, check_password_hash
from . import db
from . import ma


class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(30))
    content = db.Column(db.Text())
    cre_datetime = db.Column(db.DateTime(), default=datetime.now)

    def __init__(self, title):
        self.title = title

    def __repr__(self):
        return '<Post> %r' % self.title

    def to_sjon(self):
        return {
            'id': self.id,
            'title': self.title,
            'content': self.content,
            'cre_datetime': self.cre_datetime
        }


class PostSchema(ma.Schema):
    class Meta:
        fields = ('id', 'title', 'content', 'cre_datetime')


post_schema = PostSchema()
posts_schema = PostSchema(many=True)
